home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / irc / HVHiP.lha / HVHiP.amirx
Encoding:
Text File  |  1998-10-05  |  15.7 KB  |  678 lines

  1. /* HVHiP.AMIRX by Johan Forsberg & Daniel Widerström
  2. $VER: HVHiP.amirx 1.0 (98.10.05)
  3.  
  4. What?
  5. ----------------------------------------------------------------
  6. A convenient way to play High Voltage SIDs (or possibly other 
  7. SIDs :) in HippoPlayer, without leaving AmIRC or even touching
  8. that awful mouse thingy. Theoretically it could be used for
  9. other kinds of music modules too... but hey, that's not what 
  10. it's for!
  11.  
  12.  
  13. Well?
  14. ----------------------------------------------------------------
  15. 0: Get the High Voltage SID Collection... but we assume you've
  16.    already got that. Hasn't everybody? :)
  17.    You can find them at:
  18.        http://www.dhp.com/~shark/c64music/hv_sids/
  19.    if you don't. You don't actually *need* to have all of them
  20.    for this script to work, but you can never have too many
  21.    SIDs, so why not grab'em?
  22.  
  23. 1: Put this script in .../AmIRC/rexx/
  24.  
  25. 2: Get "grep" and put it somewhere in your path (C: maybe?)
  26.    Should be GNU grep, or else you'll probably have to modify
  27.    the call. SAS grep can be made to work, anyway. GNU grep
  28.    can be found on Aminet and is much faster than AmigaDOS'
  29.    'search' command.
  30.  
  31. 3: Add an alias to AmIRC, for example:
  32.       /alias sid /rx HVHiP.AMIRX %p
  33.    Make sure you have SYS:System/RexxMast running (put it in 
  34.    your startup somewhere, perhaps).
  35.  
  36. 4: Set your HV SIDs path by writing (in AmIRC):
  37.       /sid -setpath Your:High/Voltage/SIDs/Path/C64Music/
  38.  
  39.    ...your HippoPlayer path:
  40.       /sid -sethip Your:Hippo/Player/Path/
  41.  
  42.    ...decide whether you'd like HVHiP to echo everything:
  43.       /sid -setecho 0    *or*    /sid -setecho 1
  44.  
  45.    ...set the message type for AmIRC echoes:
  46.       /sid -setcolor 4   (Argument range is 1-7)
  47.  
  48.    ...set maximum number of hits reported in AmIRC:
  49.       /sid -setmax 50
  50.  
  51.  
  52. 5: Whenever you're ready for some SID action, simply type
  53.        /sid Whatever
  54.    This will cause the script to look for a SID with a name
  55.    containing the word "whatever" (the search is not case
  56.    sensitive.) Because grep is used for matching words, you
  57.    can utilize grep's regular expressions for some advanced
  58.    searching. If you only want the script to play SIDs which
  59.    exactly match the name you gave, you might want to write:
  60.        /sid /Commando.sid
  61.    Oh, and as a side effect, you're able to search for authors
  62.    in the same way, i.e:
  63.        /sid Hubbard_Rob/
  64.  
  65.    There are a couple of commands you can pass to the script.
  66.    Some of them require an argument:
  67.      P = search pattern, S = string, N = number, [] = optional
  68.  
  69.    -add P      Just add files, don't play them
  70.    -new [P]    Clears playlist before adding any new ones
  71.    -rand       Randomly selects/plays another SID from the list.
  72.    -next       Selects/plays next song from list.
  73.    -prev       Selects/plays prev song from list.
  74.    -nsub       Selects/plays next subsong
  75.    -psub       Selects/plays prev subsong
  76.    -sub [N]    Selects/plays arg. (No arg plays 1)
  77.    -pause      Toggle pause on/off in HiP
  78.    -sort       Sort your playlist alphabetically
  79.    -test P     Makes the search, but won't add any files to HiP.
  80.    -setpath S  Sets your HVSids path. Specify path as second argu-
  81.                ment, and remember that the "C64Music" directory
  82.                must be *included* in the path.
  83.    -setecho N  Sets whether you want the search results echoed in
  84.                your AmIRC view or not. Second argument should be
  85.                either 0 or 1.
  86.    -sethip S   Sets Hippoplayer path, don't have Hip in it
  87.    -setcolor N Set color type to use in AmIRC messages.
  88.    -setmax N   Set max sid to echo when setecho is 1.
  89.    -prefs      Echo your prefs
  90.  
  91.    Commands are optional, but you can only give one command
  92.    at a time. The command must be put before any search pattern.
  93.    Don't forget the "-" before a command, or it will be inter-
  94.    preted as a search pattern. If neither commands or arguments
  95.    are passed, a list of available commands is echoed.
  96.  
  97.    All the settings are stored in an environment variable called
  98.    "HVHiP.prefs". The script also generates an index file over
  99.    your HV SIDs directory which is called "S:hvSIDs.index", and
  100.    temporarily stores grep output in T:. The index file is auto-
  101.    matically generated the first time you run the script (or if
  102.    the index is missing - remove the index every time you update
  103.    your HV SIDs if you want the script to be up-to-date) which
  104.    might take a few minutes.
  105.  
  106.  
  107. Why?
  108. ----------------------------------------------------------------
  109. Because we just love Sids, HippoPlayer and IRC :)
  110. And because it's so pointless it just had to be done.
  111.  
  112.  
  113. Who?
  114. ----------------------------------------------------------------
  115. Johan Forsberg (Johan.Forsberg.6117@student.uu.se), who started
  116. writing the script, and Daniel Widerström (rutgers@mhd.mh.se)
  117. who came up with the original idea and got involved in writing
  118. it too. Both are often found on IRC, mainly on IRCNet/#AmigaSWE
  119. under aliases "Agrajag" and "Rutgers", respectively.
  120.  
  121.  
  122. When?
  123. ----------------------------------------------------------------
  124. 1.0  Final release, uploaded to Aminet. (D)
  125.  
  126. 0.3  some refinements of the "readme" part and small cleanup (J)
  127.      some betatesting has been made :)
  128.  
  129. 0.24 added -psub (D)
  130.      added -setcolor (D)
  131.      added -setmax (D)
  132.      added -sub (D)
  133.      added -add (D)
  134.      fix bugg when command -command isn't support (D)
  135.  
  136. 0.23 added -sort (D)
  137.      added -nsub (D)
  138.      fixed broken -test (J)
  139.  
  140. 0.22 automatically generate s:hvsids.index (J)
  141.      Start HiP if isn't running (D)
  142.      added -prefs (D)
  143.      change prefs write, and add Hippoplayer path (D)
  144.      change -next to -rand and -next is really next now (D)
  145.      added -prev (D)
  146.  
  147. 0.21 fix check if Hippoplayer is running (D)
  148.      Don't search for "" (D)
  149.  
  150. 0.2  translated the manual into english (J)
  151.      put some user prefs in an environment variable (J)
  152.      added -setpath (J)
  153.      added -setecho (J)
  154.      added -test (J)
  155.      some lame errorchecking (J)
  156.      general cleanup (J)
  157.  
  158. 0.13 got rid of a bug that caused HiP to go wild when no Sid
  159.      would match the given word. Stupid! (J)
  160.  
  161. 0.12 added version with no argument (D)
  162.      added command interpreter (D)
  163.      added -new (D)
  164.      added -next (D)
  165.      added -pause (D)
  166.  
  167. 0.11 added check whether Hippoplayer is running (D)
  168.      added credits for Daniel Widerström (Daniel)
  169.      
  170. 0.1  first alpha version (*very* basic) (Johan)
  171.  
  172.  
  173. Whoops?
  174. ----------------------------------------------------------------
  175. This piece of software is completely free and you can do with it
  176. whatever you like. However, we do not take *any* responsibility
  177. for what might happen if you use it, even if you follow all
  178. instructions to the letter. This script works pretty well on
  179. our machines, but it might very well blow up in your face. So
  180. be warned. Not that anything bad actually *will* happen. :)
  181. But if it should bomb for whatever reason, you might want to
  182. tell us about it, even if you can fix the problem by yourself.
  183. That way someone else with the same problem might be helped too!
  184. Also, none of us are too well aquainted with ARexx, so if you
  185. happen to be a real guru, and spot something stupid, ineffective
  186. or downright dangerous in the code - why not drop us a line?
  187. Any other comments or suggestions of any kind are most welcome!
  188.  
  189.  
  190. TODO :
  191. ----------------------------------------------------------------
  192. More testing
  193. add -next|-prev|etc. can take [N]
  194. Probably should add more errorchecking... D'oh!
  195.  
  196. */
  197.  
  198. version='1.0 (98.10.05)'
  199.  
  200. Hip_path=''
  201.  
  202. HVSids_path=''
  203.  
  204. echo=''
  205.  
  206. maxsid=''
  207.  
  208. colorecho=''
  209.  
  210. options results
  211.  
  212. PARSE ARG Arg1 Arg2
  213.  
  214. Arg1=strip(Arg1)
  215. Arg2=strip(Arg2)
  216.  
  217. amirc_host=address()
  218.  
  219. /*Check for commands involving prefs...*/
  220.  
  221. if Arg1="-setpath" then do
  222.    HVSids_path=Arg2
  223.    call WritePrefs
  224.    call write "Setting path..."
  225.    exit
  226. end
  227.  
  228. if Arg1="-setecho" then do
  229.    echo=Arg2
  230.    call write "Setting echo..."
  231.    call WritePrefs   
  232.    exit
  233. end
  234.  
  235. if Arg1="-sethip" then do
  236.    Hip_path=Arg2
  237.    call write "Setting Hip..."
  238.    call WritePrefs
  239.    exit
  240. end
  241.  
  242. if Arg1="-setcolor" then do
  243.    colorecho=Arg2
  244.    call write "Setting color..."
  245.    call WritePrefs
  246.    exit
  247. end
  248.  
  249. if Arg1="-setmax" then do
  250.    maxsid=Arg2
  251.    call write "Setting max..."
  252.    call WritePrefs
  253.    exit
  254. end
  255.  
  256. /* call WRITE "Hejsan!" */
  257.  
  258.  
  259. if open(prefs,'ENV:HVHiP.prefs',R) then do
  260.  
  261.    HVSids_path=readln(prefs)
  262.    Hip_path=readln(prefs)
  263.    echo=readln(prefs)
  264.    colorecho=readln(prefs)
  265.    maxsid=readln(prefs)
  266.  
  267.    close(prefs)
  268.  
  269.    if echo='' then echo=0
  270.    if colorecho='' then colorecho=2
  271.    if maxsid='' then maxsid=50
  272.  
  273.    if Arg1="-prefs" then do
  274.       call write "HVSid Path = "HVSids_path
  275.       call Write "Hippoplayer Path = "Hip_path
  276.       call write "Write Echo = "echo
  277.       call write "Echo ColorType = "colorecho
  278.       call write "Echo Max = "maxsid
  279.       exit
  280.    end
  281.  
  282.    /* Check if any arg */
  283.  
  284.    if Arg1="" then DO
  285.  
  286.      Call VERSION
  287.      Call USAGE
  288.      EXIT
  289.    END
  290.  
  291.    if HVSids_path='' then do
  292.       call write "Your HVSids path is empty!"
  293.       EXIT
  294.    end
  295.  
  296.    if hip_path='' then do
  297.       call write "Your Hippoplayer path is empty!"
  298.       EXIT
  299.    end
  300.  
  301.    /*If the index file doesn't exist - create it!*/
  302.  
  303.    if ~(open(index,'s:hvsids.index',R)) then do
  304.       
  305.       call write "Index file missing - creating it (may take a few minutes...)"
  306.       
  307.       address command 'cd 'HVSids_path '0a'x 'list lformat=%P%N all files >t:hvindex.tmp'
  308.       address command 'sort t:hvindex.tmp to s:hvsids.index'
  309.       address command 'delete t:hvindex.tmp'
  310.  
  311.    end
  312.  
  313.    else close(index)
  314.  
  315.    /*Check for commands*/
  316.  
  317.    argtemp=left(Arg1,1)
  318.  
  319.    if argtemp="-" then do
  320.  
  321.       if ~(Arg1="-test") then do
  322.         err=show('P','HIPPOPLAYER')
  323.  
  324.         if err=0 then do
  325.           call write "Starting HippoPlayer..."
  326.           address command ''hip_path'hip'
  327.           address command 'WaitForPort HIPPOPLAYER'
  328.         END
  329.       END
  330.  
  331.       address 'HIPPOPLAYER'
  332.  
  333.       SELECT
  334.  
  335.         When Arg1="-rand" then do
  336.           'RANDPLAY'
  337.           EXIT
  338.  
  339.         END
  340.  
  341.         When Arg1="-next" then do
  342.  
  343.           address value amirc_host
  344.           getchannel
  345.           address
  346.  
  347.           GET NFIL
  348.           maxmod = result
  349.  
  350.           GET CFIL
  351.           current = result
  352.  
  353.           CHOOSE current+1
  354.           IF current+1 > maxmod then 'CHOOSE' 1
  355.  
  356.           'PLAY'
  357.  
  358.           EXIT
  359.         END
  360.  
  361.         When Arg1="-prev" then do
  362.  
  363.           address value amirc_host
  364.           getchannel
  365.           address
  366.  
  367.           GET CFIL
  368.           current = result
  369.  
  370.           CHOOSE current-1
  371.  
  372.           'PLAY'
  373.  
  374.           EXIT
  375.         END
  376.  
  377.         When Arg1="-nsub" then do
  378.  
  379.           address value amirc_host
  380.           getchannel
  381.           address
  382.  
  383.  
  384.           GET NSNG
  385.           maxsong = result
  386.  
  387.           GET CSNG
  388.           current = result
  389.  
  390.           IF (current+1) > maxsong then SONGPLAY 0
  391.           ELSE SONGPLAY (current+1)
  392.  
  393.           EXIT
  394.         END
  395.  
  396.         When Arg1="-psub" then do
  397.  
  398.           address value amirc_host
  399.           getchannel
  400.           address
  401.  
  402.           GET CSNG
  403.           current = result
  404.  
  405.           GET NSNG
  406.           maxsong = result
  407.  
  408.           IF (current) < 2 THEN SONGPLAY maxsong
  409.           ELSE SONGPLAY (current-1)
  410.  
  411.           EXIT
  412.         END
  413.  
  414.         When Arg1="-sub" then do
  415.  
  416.           address value amirc_host
  417.           getchannel
  418.           address
  419.  
  420.           GET NSNG
  421.           maxsong = result
  422.  
  423.           if ARG2 > maxsong then SONGPLAY maxsong
  424.           ELSE SONGPLAY ARG2
  425.  
  426.           EXIT
  427.         END
  428.  
  429.         When Arg1="-sort" then do
  430.  
  431.           call write "sort songs"
  432.  
  433.           'SORT'
  434.           EXIT
  435.         END
  436.  
  437.         When Arg1="-new" then do
  438.  
  439.           'CLEAR'
  440.           'EJECT'
  441.           if Arg2="" then exit
  442.         END
  443.  
  444.         When Arg1="-pause" then do
  445.  
  446.           address value amirc_host
  447.  
  448.           getchannel
  449.   
  450.           address
  451.           
  452.           get play
  453.           
  454.           if result == 1 then 'STOP'
  455.           ELSE 'CONT'
  456.  
  457.           EXIT
  458.  
  459.         END
  460.  
  461.         When Arg1="-test" then do
  462.         
  463.         END
  464.  
  465.         When Arg1="-add" then do
  466.  
  467.         END
  468.  
  469.         OTHERWISE
  470.  
  471.         address value amirc_host
  472.  
  473.         call write "command "arg1" is not supported"
  474.  
  475.         EXIT
  476.         END
  477.  
  478.    END
  479.  
  480.    /*No commands specified?*/
  481.  
  482.    ELSE DO
  483.       Arg2=Arg1
  484.    END
  485.  
  486.  
  487.    /*Get down to business...*/
  488.  
  489.    if echo=1 then call version
  490.  
  491.    address command 'grep -i "'Arg2'" s:hvsids.index >t:HVgrep.tmp'
  492.  
  493.    i=1     /*Counter*/
  494.  
  495.    if open(temp,'t:HVgrep.tmp',R) then do
  496.  
  497.       /*Get results from grep search...*/
  498.  
  499.       do until eof(temp)
  500.          path.i=readln(temp)
  501.          i=i+1
  502.       end
  503.  
  504.       close(temp)
  505.  
  506.       address command 'delete t:HVgrep.tmp QUIET'
  507.  
  508.       /*...if there _were_ any results...*/
  509.  
  510.       if i>2 then do
  511.  
  512.          if ~(Arg1="-test") then do
  513.            err=show('P','HIPPOPLAYER')
  514.  
  515.            if err=0 then do
  516.              call write "HippoPlayer isn't running! I'll try to start it..."
  517.              address command ''hip_path'hip'
  518.              address command 'WaitForPort HIPPOPLAYER'
  519.            END
  520.          END
  521.  
  522.          address 'HIPPOPLAYER'
  523.  
  524.          n=1    /*Other counter*/
  525.  
  526.          do until n = i-1
  527.  
  528.             /*Add files to Hippo*/
  529.  
  530.             if ~(Arg1="-test") then do
  531.                address 'HIPPOPLAYER'
  532.                add HVSids_path || path.n
  533.             end
  534.  
  535.             /*Echo filenames to AmIRC*/
  536.  
  537.             if echo=1 & n<maxsid+1 then do
  538.                address value Amirc_host
  539.                "echo P="n" C="colorecho" "path.n""
  540.             end
  541.  
  542.             n=n+1
  543.          end
  544.  
  545.          /*Play it, Sam*/
  546.  
  547.          if ~(Arg1="-test") & ~(Arg1="-add") then do
  548.            address 'HIPPOPLAYER'
  549.            choose 1
  550.            play
  551.          END
  552.  
  553.          address
  554.  
  555.          if (Arg1="-test"|n>maxsid+1) then Call write "---File count: "n-1"---"
  556.  
  557.       end
  558.  
  559.       else call write "Sorry, no HVSids found matching '"Arg2"'"
  560.  
  561.    end
  562.  
  563.    ELSE DO
  564.       "ECHO P=DEBUG Something weird has occurred!"
  565.       EXIT
  566.    end
  567.  
  568. end
  569.  
  570. else call write "No prefs variable found! Please create one, using -setXXX commands."
  571.  
  572. EXIT
  573.  
  574.  
  575. /* Functions */
  576.  
  577. WritePrefs:
  578.  
  579. /*Updates/creates the envvar "HVHiP.prefs" with current settings*/
  580.  
  581. if open(prefs,'ENV:HVHiP.prefs',R) then do
  582.  
  583.    if HVSids_path='' then HVSids_path=readln(prefs)
  584.       else readln(prefs)
  585.  
  586.    if Hip_path='' then Hip_path=readln(prefs)
  587.       else readln(prefs)
  588.  
  589.    if echo='' then echo=readln(prefs)
  590.       else readln(prefs)
  591.  
  592.    if colorecho='' then colorecho=readln(prefs)
  593.       else readln(prefs)
  594.  
  595.    if maxsid='' then maxsid=readln(prefs)
  596.       else readln(prefs)
  597.  
  598.    close(prefs)
  599.  
  600.    open(prefs,'ENV:HVHiP.prefs',W)
  601.    writeln(prefs,HVSids_path)
  602.    writeln(prefs,Hip_path)
  603.    writeln(prefs,echo)
  604.    writeln(prefs,colorecho)
  605.    writeln(prefs,maxsid)
  606.  
  607. end
  608.  
  609. else do
  610.  
  611.    open(prefs,'env:HVHiP.prefs',W)
  612.    writeln(prefs,HVSids_path)
  613.    writeln(prefs,Hip_path)
  614.    writeln(prefs,echo)
  615.    writeln(prefs,colorecho)
  616.    writeln(prefs,maxsid)
  617.  
  618. end
  619.  
  620. close(prefs)
  621.  
  622. address command 'copy ENV:hvsids.prefs ENVARC:hvsids.prefs'
  623.  
  624. return
  625.  
  626.  
  627. ADD:
  628.  
  629. n=1
  630.  
  631. do until n = i-1
  632.   add HVSids_path || path.n
  633.   n=n+1
  634. end
  635.  
  636. RETURN
  637.  
  638.  
  639. WRITE:
  640.  
  641. parse arg text
  642.  
  643. address value amirc_host
  644.  
  645. if colorecho='' then "ECHO P=HVHiP C=2 "text  
  646. ELSE "ECHO P=HVHiP C="colorecho text
  647.  
  648. address
  649.  
  650. RETURN
  651.  
  652.  
  653. VERSION:
  654. call write "---High-Voltage-Hippo--- "version
  655. RETURN
  656.  
  657. USAGE:
  658. call write "Command overview:"
  659. call write "-add P          add SID to list"
  660. call write "-new [P]        clear list"
  661. call write "-rand           play a random song"
  662. call write "-next           next song"
  663. call write "-prev           prev song"
  664. call write "-nsub           next subsong"
  665. call write "-psub           prev subsong"
  666. call write "-sub [N]        select arg subsong"
  667. call write "-pause          pause/continue play"
  668. call write "-sort           sort playlist alphabetically"
  669. call write "-test P         just check, don't play"
  670. call write "-setpath S      change HVSids path"
  671. call write "-setecho N      change echo (0|1)"
  672. call write "-sethip S       change Hippoplayer path"
  673. call write "-setcolor N     change colortype for echo"
  674. call write "-setmax N       change max number to echo"
  675. call write "-prefs          echo your prefs "
  676. RETURN
  677.  
  678.